﻿
Imports MySql.Data.MySqlClient
Imports System.IO
Imports System.Data
Public Class add_department_group
    Dim sql As MySqlConnection
    Dim idkey As String
    Dim ipconnect As String
    Dim usernamedb As String
    Dim dbname As String
    Dim mysqlpass As String
    Dim id_user As String
    Dim position_user As String

    Public Sub New(ByRef mysql_pass As String, ByRef ip_connect As String, ByRef user_namedb As String, ByRef db_name As String)
        InitializeComponent()
        mysqlpass = mysql_pass
        ipconnect = ip_connect
        usernamedb = user_namedb
        dbname = db_name
    End Sub
    Private Sub add_department_group_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        sql = New MySqlConnection
        sql.ConnectionString = "server=" + ipconnect + ";user id=" + usernamedb + ";password=" + mysqlpass + ";database=" + dbname + ";Character Set =utf8;"
        Try
            sql.Open()
            ' MsgBox("CONNECTED TO DATABASE")
        Catch ex As Exception
            MsgBox("Can't Connect to database" + ex.Message)

            Me.Close()
        End Try

        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearch.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where (type like '%" + key + "%' or  name like '%" + key + "%'  or  model like '%" + key + "%'   or  c_cpu like '%" + key + "%'  or  c_mainboard like '%" + key + "%' or  c_ram like '%" + key + "%' or  c_harddisk like '%" + key + "%' or  c_vgacard like '%" + key + "%'  or  state_device like '%" + key + "%' or  p_type like '%" + key + "%'or  m_size like '%" + key + "%' or  detail like '%" + key + "%'or  c_ipnumber like '%" + key + "%' or  c_ps like '%" + key + "%' or  c_cd like '%" + key + "%' or  c_case like '%" + key + "%' or  serialnumber like '%" + key + "%' or  c_comname like '%" + key + "%' or  c_windows like '%" + key + "%' or  c_office like '%" + key + "%') and state_device = 'ว่าง' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewshow.Items.Clear()

            While (mySqlReader.Read())

                With ListViewshow.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If
                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM department order by idDepartment;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewdp.Items.Clear()

            While (mySqlReader.Read())

                With ListViewdp.Items.Add(mySqlReader("idDepartment"))
                    .SubItems.Add(mySqlReader("departmentname"))

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub
    Private Sub showdata()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearch.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM data_device where (type like '%" + key + "%' or  name like '%" + key + "%'  or  model like '%" + key + "%'   or  c_cpu like '%" + key + "%'  or  c_mainboard like '%" + key + "%' or  c_ram like '%" + key + "%' or  c_harddisk like '%" + key + "%' or  c_vgacard like '%" + key + "%'  or  state_device like '%" + key + "%' or  p_type like '%" + key + "%'or  m_size like '%" + key + "%' or  detail like '%" + key + "%'or  c_ipnumber like '%" + key + "%' or  c_ps like '%" + key + "%' or  c_cd like '%" + key + "%' or  c_case like '%" + key + "%' or  serialnumber like '%" + key + "%' or  c_comname like '%" + key + "%' or  c_windows like '%" + key + "%' or  c_office like '%" + key + "%') and state_device = 'ว่าง' order by iddata_device;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand


        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewshow.Items.Clear()

            While (mySqlReader.Read())

                With ListViewshow.Items.Add(mySqlReader("iddata_device"))
                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Computer")
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Printer")
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Monitor")
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Other")
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.add("Licens")
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.add("Network")
                    End If
                    .SubItems.Add(mySqlReader("name"))

                    If mySqlReader("type") = "Computer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Monitor" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Printer" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "Other" Then
                        .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("type") = "License" Then
                        .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                    End If
                    If mySqlReader("type") = "Network" Then
                        .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                    End If
                    If mySqlReader("state_device") IsNot DBNull.Value Then
                        .SubItems.Add(mySqlReader("state_device"))
                    End If

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    Private Sub txtsearch_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearch.KeyDown
        If e.KeyCode = "13" Then
            showdata()
        End If
    End Sub

    Private Sub txtsearchdp_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtsearchdp.KeyDown
        If e.KeyCode = "13" Then
            showdatadp()
        End If
    End Sub

    Private Sub showdatadp()
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim key As String
        Dim count As Integer

        count = 0
        key = txtsearchdp.Text

        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If

        mySqlCommand.CommandText = "SELECT * FROM department where departmentname like '%" + key + "%' order by idDepartment;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand

        Try
            mySqlReader = mySqlCommand.ExecuteReader

            ListViewdp.Items.Clear()

            While (mySqlReader.Read())

                With ListViewdp.Items.Add(mySqlReader("idDepartment"))
                    .SubItems.Add(mySqlReader("departmentname"))

                End With
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    Private Sub ListViewshow_MouseDoubleClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles ListViewshow.MouseDoubleClick
        add_aoi()
        'เรียกข้อมูลอีอ้อย
        Dim Listview3_Index As Integer
        Listview3_Index = ListViewshow.SelectedIndices(0)
        ListViewshow.Items.RemoveAt(Listview3_Index)
    End Sub

    Private Sub add_aoi()
        Dim iddata_device As String = ListViewshow.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim CheckIndex As Integer
        Dim i As Integer
        Dim CheckData As Boolean

        CheckData = False
        CheckIndex = ListViewshowdata.Items.Count


        For i = 0 To CheckIndex - 1
            If iddata_device <> ListViewshowdata.Items(i).SubItems(0).Text Then

                CheckData = True

            Else

                CheckData = False
                Exit For
            End If
        Next i

        If CheckData = False And CheckIndex <> 0 Then
            MsgBox("มีรายชื่อนี้อยู่แล้ว", MsgBoxStyle.Information + MsgBoxStyle.OkOnly, "Warning Message")

        End If

        If CheckData = True Or CheckIndex = 0 Then


            Dim mySqlCommand As New MySqlCommand
            Dim mySqlAdaptor As New MySqlDataAdapter
            Dim mySqlReader As MySqlDataReader

            'mySqlCommand.CommandText = "SELECT DISTINCT * from Employee where dept_id in (SELECT dept_id from Department where dept_name like" + " '%" + TextBox1.Text + "%' )" + " or emp_name like " + "'%" + TextBox1.Text + "%'" + " or emp_surname like " + "'%" + TextBox1.Text + "%'" + " or emp_position like " + "'%" + TextBox1.Text + "%'" + " or emp_level like " + "'%" + TextBox1.Text + "%'" + ";"
            mySqlCommand.CommandText = "SELECT * FROM data_device where iddata_device= '" & iddata_device & "';"
            ' mySqlCommand.CommandText = 
            mySqlCommand.Connection = sql
            mySqlAdaptor.SelectCommand = mySqlCommand

            Try
                mySqlReader = mySqlCommand.ExecuteReader


                While (mySqlReader.Read())

                    With ListViewshowdata.Items.Add(mySqlReader("iddata_device"))
                        If mySqlReader("type") = "Computer" Then
                            .SubItems.Add("Computer")
                        End If
                        If mySqlReader("type") = "Printer" Then
                            .SubItems.Add("Printer")
                        End If
                        If mySqlReader("type") = "Monitor" Then
                            .SubItems.Add("Monitor")
                        End If
                        If mySqlReader("type") = "Other" Then
                            .SubItems.Add("Other")
                        End If
                        If mySqlReader("type") = "License" Then
                            .SubItems.add("Licens")
                        End If
                        If mySqlReader("type") = "Network" Then
                            .SubItems.add("Network")
                        End If
                        .SubItems.Add(mySqlReader("name"))

                        If mySqlReader("type") = "Computer" Then
                            .SubItems.Add("Model : " + mySqlReader("model") + "CPU : " + mySqlReader("c_cpu") + "mainboard : " + mySqlReader("c_mainboard") + "RAM : " + mySqlReader("c_ram") + "HARDDISK : " + mySqlReader("c_harddisk") + "VGA Card : " + mySqlReader("c_vgacard") + "Ip Number : " + mySqlReader("c_ipnumber") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "PowerSupply : " + mySqlReader("c_ps") + "CD/DVD : " + mySqlReader("c_cd") + "Case : " + mySqlReader("c_case") + "IpAddress : " + mySqlReader("c_ipnumber") + "Computername : " + mySqlReader("c_comname") + " Windows : " + mySqlReader("c_windows") + "Office : " + mySqlReader("c_office") + "Price : " + mySqlReader("price"))
                        End If
                        If mySqlReader("type") = "Monitor" Then
                            .SubItems.Add("Model : " + mySqlReader("model") + "Size : " + mySqlReader("m_size") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                        End If
                        If mySqlReader("type") = "Printer" Then
                            .SubItems.Add("Model : " + mySqlReader("model") + "Type : " + mySqlReader("p_type") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                        End If
                        If mySqlReader("type") = "Other" Then
                            .SubItems.Add("Model : " + mySqlReader("model") + "Detail : " + mySqlReader("detail") + "Serial Number : " + mySqlReader("serialnumber") + "Price : " + mySqlReader("price"))
                        End If
                        If mySqlReader("type") = "License" Then
                            .SubItems.Add("Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price") + "Amount : " + mySqlReader("amount"))
                        End If
                        If mySqlReader("type") = "Network" Then
                            .SubItems.Add("Serial Number : " + mySqlReader("serialnumber") + "IP Address : " + mySqlReader("c_ipnumber") + "Pass-Connect : " + mySqlReader("pass_connect") + "Pass-Config : " + mySqlReader("pass_config") + "Detail : " + mySqlReader("detail") + "Price : " + mySqlReader("price"))
                        End If
                        If mySqlReader("state_device") IsNot DBNull.Value Then
                            .SubItems.Add(mySqlReader("state_device"))
                        End If
                    End With
                End While
            Catch ex As Exception
                MsgBox(ex.ToString)
                MsgBox("ห้ามใส่เครื่องหมาย ' ในช่องค้นหา", MsgBoxStyle.Critical + MsgBoxStyle.OkOnly, "Warning Message")
            End Try
            sql.Close()
        End If
    End Sub

    Private Sub ListViewdp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewdp.Click
        idkey = ListViewdp.SelectedItems(0).SubItems(0).Text
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        mySqlCommand.CommandText = "SELECT * FROM department where idDepartment = '" & idkey & "' ;"
        ' mySqlCommand.CommandText = 
        mySqlCommand.Connection = sql
        mySqlAdaptor.SelectCommand = mySqlCommand
        Try
            mySqlReader = mySqlCommand.ExecuteReader
            While (mySqlReader.Read())
                tab1iddp.Text = mySqlReader("idDepartment")
                tab1dpname.Text = mySqlReader("departmentname")
            End While
        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try
        sql.Close()
    End Sub

    Private Sub btnsearchdp_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearchdp.Click
        showdatadp()
    End Sub

    Private Sub btnsearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsearch.Click
        showdata()
    End Sub

    Private Sub btnsave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnsave.Click
        Dim mySqlCommand As New MySqlCommand
        Dim mySqlAdaptor As New MySqlDataAdapter
        Dim mySqlReader As MySqlDataReader
        Dim size As String
        Dim condition As String
        Dim respone As Object
        Dim commandText As String
        Dim commandText2 As String
        Dim commandText3 As String
        Dim counter1 As Integer = 0
        If sql.State = ConnectionState.Closed Then
            sql.Open()
        End If
        respone = MsgBox("ยืนยันข้อมูลถูกต้อง by โตน ลูกพี่อารี", MsgBoxStyle.OkCancel + MsgBoxStyle.Information, "Warning Messsage")

        For counter1 = 0 To ListViewshowdata.Items.Count - 1

            If sql.State = ConnectionState.Closed Then
                sql.Open()
            End If
            '  mySqlCommand.CommandText = "INSERT INTO Training VALUES ('" + selectedTrainee + "', '" + selectedCourse + +"', '" + DateTimePicker1.Value.ToString() + "', '" + NumericUpDown1.Value.ToString() + "', '" + NumericUpDown2.Value.ToString() + "', '" + NumericUpDown3.Value.ToString() + "." + NumericUpDown4.Value.ToString() + "','" + trainingHour + "','" + CheckBox1.Checked.ToString() + "');"

            'MsgBox("INSERT INTO training (emp_code,course_id,training_date,time_start,time_end,training_hours,training_approve) VALUES ('" & selectedTrainee & "', '" & selectedCourse & "', '" & DateTimePicker1.Value.Year.ToString() & "-" & DateTimePicker1.Value.Month.ToString() & "-" & DateTimePicker1.Value.Day.ToString() & "', '" & NumericUpDown1.Value & "." & NumericUpDown2.Value & "', '" & NumericUpDown3.Value & "." & NumericUpDown4.Value & "', '" & trainingHour & "'," & checkedApprove & ");")

            commandText = "UPDATE data_device SET state_device = 'ถูกใช้งาน' , idDepartment = '" & tab1iddp.Text & "',dd_detail = '" & tab1dpdetail.Text & "' WHERE iddata_device = '" & ListViewshowdata.Items(counter1).SubItems(0).Text & "' "
            mySqlCommand.CommandText = commandText
            mySqlCommand.CommandType = CommandType.Text
            mySqlCommand.Connection = sql
            mySqlCommand.ExecuteNonQuery()
            sql.Close()

            If sql.State = ConnectionState.Closed Then
                sql.Open()
            End If
            Try
                mySqlCommand.CommandText = "INSERT INTO device_department (iddata_device,idDepartment,dd_detail,date_time_book) VALUES ('" & ListViewshowdata.Items(counter1).SubItems(0).Text & "',  '" & tab1iddp.Text & "','" & tab1dpdetail.Text & "','" & Date.Now.ToString & "');"
                mySqlCommand.CommandType = CommandType.Text
                mySqlCommand.Connection = sql
                mySqlCommand.ExecuteNonQuery()

            Catch ex As Exception
                MsgBox(ex.ToString)
                sql.Close()
            End Try
            sql.Close()
        Next counter1
        ListViewshowdata.Items.Clear()
        tab1iddp.Text = ""
        tab1dpname.Text = ""
        tab1dpdetail.Text = ""
    End Sub

    

    Private Sub เพมขอมลอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมขอมลอปกรณToolStripMenuItem.Click
        Dim NextForm As add = New add(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        Me.Hide()
        NextForm.ShowDialog()
    End Sub

    Private Sub แกไขขอมลอปกรToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขขอมลอปกรToolStripMenuItem.Click
        Dim NextForm As Edit2 = New Edit2(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub เพมแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles เพมแผนกToolStripMenuItem.Click
        Dim NextForm As Adddepartment = New Adddepartment(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub จองอปกรณToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles จองอปกรณToolStripMenuItem.Click
        Dim NextForm As device_department = New device_department(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub แกไขแผนกToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles แกไขแผนกToolStripMenuItem.Click
        Dim NextForm As showdetail = New showdetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub บนทกประวตบำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บนทกประวตบำรงรกษาToolStripMenuItem.Click
        Dim NextForm As historydetail = New historydetail(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub

    Private Sub ListViewshowdata_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles ListViewshowdata.DoubleClick
        ListViewshowdata.SelectedItems(0).Remove()
        showdata()
    End Sub

    Private Sub บำรงรกษาToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles บำรงรกษาToolStripMenuItem.Click
        Dim NextForm As addhistory = New addhistory(mysqlpass, ipconnect, usernamedb, dbname)
        '  Dim NextForm As main_user = New main_user()
        NextForm.Show()
        Me.Hide()
    End Sub
End Class